meta %>%
filter(su_block == 1) %>%
select(varname, about) %>% as.list()
## $varname
## [1] "h_geocode" "avgc_all" "medc_all"
## [4] "commutersInBlockall" "avgc_within40" "medc_within40"
## [7] "commuterw40" "avgc_25_employees" "medc_25_employees"
## [10] "commuter25" "avgc_workinRegion" "medc_workinRegion"
## [13] "commuterinRegion"
##
## $about
## [1] "15-digit census block code of where the indivudals of a given work census block live (resident census block)"
## [2] "Average \"as the crow flies\" commuting distance for all workers in the census block"
## [3] "Median \"as the crow flies\" commuting distance for all workers in the census block"
## [4] "The number of workers in each census block who are represented in the data"
## [5] "Average \"as the crow flies\" commuting distance for residents of the census block who work within 40 miles"
## [6] "Median \"as the crow flies\" commuting distance for residents of the census block who work within 40 miles"
## [7] "The number of residents in the census block who work within 40 miles of home"
## [8] "Average \"as the crow flies\" commuting distance for residents of the census block who commute to a census tract that employs at least 25 residents from the region of interest"
## [9] "Median \"as the crow flies\" commuting distance for residents of the census block who commute to a census tract that employs at least 25 residents of the region of interest"
## [10] "The number of residents of the census block who commute to a census tract that employs at least 25 residents of the region of interest"
## [11] "Average \"as the crow flies\" commuting distance for residents of the census block who work in the same region as where they live"
## [12] "Median \"as the crow flies\" commuting distance for residents of the census block who work in the same region as where they live"
## [13] "The number of residents of the census block who commute to work within the region of interest"
glimpse(lodes)
## Rows: 2,098
## Columns: 13
## $ h_geocode <dbl> 5.100109e+14, 5.100109e+14, 5.100109e+14, 5.100109…
## $ avgc_all <dbl> 67.2254428, 58.0150779, 59.3763010, 145.8265361, 4…
## $ medc_all <dbl> 67.2254428, 26.7085805, 23.5838705, 145.8265361, 2…
## $ commutersInBlockall <int> 2, 23, 12, 2, 27, 1, 13, 33, 1, 21, 1, 11, 14, 6, …
## $ avgc_within40 <dbl> 12.1746326, 13.4734848, 11.9823106, NA, 10.6085612…
## $ medc_within40 <dbl> 12.1746326, 13.5817744, 11.0125130, NA, 2.5812295,…
## $ commuterw40 <int> 1, 14, 8, NA, 15, 1, 9, 22, 1, 8, NA, 8, 9, 3, 2, …
## $ avgc_25_employees <dbl> 12.1746326, 17.1280824, 19.4350416, 155.2279315, 2…
## $ medc_25_employees <dbl> 12.1746326, 13.5896603, 20.4542314, 155.2279315, 2…
## $ commuter25 <int> 1, 15, 9, 1, 21, 1, 9, 23, 1, 13, 1, 8, 10, 5, 2, …
## $ avgc_workinRegion <dbl> 12.1746326, 13.4734848, 11.9823106, NA, 18.0882298…
## $ medc_workinRegion <dbl> 12.1746326, 13.5817744, 11.0125130, NA, 13.4601519…
## $ commuterinRegion <int> 1, 14, 8, NA, 19, 1, 9, 22, 1, 8, NA, 8, 9, 3, 2, …
lodes %>% select(avgc_all, avgc_within40, avgc_25_employees, avgc_workinRegion, medc_all, medc_within40, medc_25_employees, medc_workinRegion) %>%
select(where(~is.numeric(.x))) %>%
as.data.frame() %>%
stargazer(., type = "text", title = "Summary Statistics", digits = 2,
summary.stat = c("mean", "sd", "min", "median", "max"))
##
## Summary Statistics
## ===================================================
## Statistic Mean St. Dev. Min Median Max
## ---------------------------------------------------
## avgc_all 44.10 39.54 0.21 35.83 425.90
## avgc_within40 9.51 6.03 0.14 8.55 39.95
## avgc_25_employees 16.88 20.70 0.07 11.05 389.78
## avgc_workinRegion 7.64 4.78 0.07 6.92 48.05
## medc_all 30.13 41.34 0.16 12.92 425.90
## medc_within40 8.33 6.50 0.14 6.67 39.95
## medc_25_employees 12.01 19.56 0.07 6.97 389.78
## medc_workinRegion 6.87 5.07 0.07 5.67 48.05
## ---------------------------------------------------
long <- lodes %>% select(c( h_geocode, avgc_all, avgc_within40, avgc_25_employees, avgc_workinRegion, medc_all, medc_within40, medc_25_employees, medc_workinRegion)) %>%
pivot_longer(-h_geocode, names_to = "measure", values_to = "value")
long$measure <- factor(long$measure,
levels = c("avgc_all", "medc_all", "avgc_within40", "medc_within40", "avgc_25_employees", "medc_25_employees", "avgc_workinRegion",
"medc_workinRegion"))
long %>%
ggplot(aes(x = value, fill = measure)) +
scale_fill_viridis(option = "plasma", discrete = TRUE, guide = FALSE) +
geom_histogram() +
facet_wrap(~measure, scales = "free", ncol = 2)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 1200 rows containing non-finite values (stat_bin).
meta %>%
filter(varname %in% c("avgc_all", "avgc_within40", "avgc_25_employees", "avgc_workinRegion", "medc_all", "medc_within40", "medc_25_employees", "medc_workinRegion")) %>%
mutate(label = paste0(varname, ": ", about)) %>%
select(label) %>%
as.list()
$label [1] "avgc_all: Average "as the crow flies" commuting distance for all workers in the census block"
[2] "medc_all: Median "as the crow flies" commuting distance for all workers in the census block"
[3] "avgc_within40: Average "as the crow flies" commuting distance for residents of the census block who work within 40 miles"
[4] "medc_within40: Median "as the crow flies" commuting distance for residents of the census block who work within 40 miles"
[5] "avgc_25_employees: Average "as the crow flies" commuting distance for residents of the census block who commute to a census tract that employs at least 25 residents from the region of interest" [6] "medc_25_employees: Median "as the crow flies" commuting distance for residents of the census block who commute to a census tract that employs at least 25 residents of the region of interest"
[7] "avgc_workinRegion: Average "as the crow flies" commuting distance for residents of the census block who work in the same region as where they live"
[8] "medc_workinRegion: Median "as the crow flies" commuting distance for residents of the census block who work in the same region as where they live"
pal <- colorNumeric("plasma", reverse = T, domain = east_lodes$avgc_all)
leaflet(east_lodes) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = east_lodes,
fillColor = ~pal(avgc_all),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("GEOID: ", east_lodes$h_geocode, "<br>",
"Average commute (mi): ", round(east_lodes$avgc_all, 2))) %>%
addLegend("bottomright", pal = pal, values = east_lodes$avgc_all,
title = "Average commute (mi)", opacity = 0.7)